package com.ytjj.qmyx.mall.controller;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.utils.TokenUtil;
import com.ytjj.qmyx.mall.model.response.IconResponse;
import com.ytjj.qmyx.mall.service.HomePageService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 客户端首页
 */
@RestController
@RequestMapping("/home/page")
public class HomePageController {

    @Resource
    private HomePageService homePageService;

    /**
     * 根据广告图位置查banner
     * @param type
     * @return
     */
    @GetMapping("/findBannersByType")
    public CommonResult findBannersByType(@RequestParam("type") Integer type) {
        return CommonResult.success(homePageService.findBannersByType(type));
    }

    /**
     * 根据图标位置查Icon
     * @param type
     * @return
     */
    @GetMapping("/findIconByType")
    public CommonResult findIconByType(@RequestParam("type") String type){
        List<IconResponse> icon = homePageService.findIconByType(type);
        if(CollectionUtils.isEmpty(icon)){
            return CommonResult.failed("查询失败");
        }
        return CommonResult.success(icon,"查询成功");
    }


    @GetMapping("/getKefuApi")
    public CommonResult<Map> getKefuApi() {
        return CommonResult.success(homePageService.getDetailById(2, TokenUtil.getAppSource()));
    }
}
